package com.sxt.obj;

import com.sxt.GameWin;
import com.sxt.utils.GameUtils;

import java.awt.*;

public class EnemyObj extends GameObj{
    //敌方飞机类


    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    public EnemyObj() {
        super();
    }

    public EnemyObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public EnemyObj(Image img, int x, int y, int width, int height, double speed, GameWin frame) {
        super(img, x, y, width, height, speed, frame);
    }

    @Override
    public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);
        y+=speed;
        //敌我飞机碰撞检测
        if(this.getRec().intersects(this.frame.planeObj.getRec())){
            GameWin.state=3;
        }
        //敌机的越界消失 判断条件 y>600 改变后的坐标（-200,-200）
        if(y>600){
            this.x=-200;
            this.y=200;
            GameUtils.removeList.add(this);
        }
        //敌方飞机和我方子弹的碰撞检测
        for (ShellObj shellobj: GameUtils.shellObjList) {
            if(this.getRec().intersects(shellobj.getRec())){
                ExplodeObj explodeObj=new ExplodeObj(x,y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);
                //不改变碰撞后的子弹和敌机 会在屏幕上留坑 所以要改变坐标 我方子弹坐标
                shellobj.setX(-100);
                shellobj.setY(100);
                //敌机坐标
                this.x=-200;
                this.y=200;
                GameUtils.removeList.add(shellobj);
                GameUtils.removeList.add(this);
                GameWin.score++;

            }

        }
    }
}
